<?php
namespace App\Models;

/**
 * 充值扣款日志类
 */
class MDebitLog extends BaseModel
{
    public $table = "debit_logs";       //指定表名

    public static $USER_RECHARGE = 0;           //会员充值标识
    public static $USER_DEDUCTING = 1;          //会员扣款标识

    /**
     * 记录一条充值/扣款日志
     * $money = 金额
     * $flag = 充值/扣款
     * $wallet_type = 钱包类型
     * $intro = 文字描述
     */
    public static function log($uid, $username, $money, $flag, $wallet_type, $intro = "")
    {
        $log = new MDebitLog();
        $log->no = onlyNo();
        $log->uid = $uid;
        $log->username = $username;
        $log->money = $money;
        $log->type = $flag;
        $log->wallet = $wallet_type;
        $log->time = time();

        $temp_ctl = "";
        if ($flag == self::$USER_RECHARGE) {
            $temp_ctl = "充值";
        } elseif ($flag == self::$USER_DEDUCTING) {
            $temp_ctl = "扣款";
        }
        $temp_wallet = "";
        if ($wallet_type == MWallet::$WALLET_TYPE_1) {
            $temp_wallet = "奖金币";
        } elseif ($wallet_type == MWallet::$WALLET_TYPE_2) {
            $temp_wallet = "报单币";
        } elseif ($wallet_type == MWallet::$WALLET_TYPE_3) {
            $temp_wallet = "购物币";
        } elseif ($wallet_type == MWallet::$WALLET_TYPE_4) {

        } elseif ($wallet_type == MWallet::$WALLET_TYPE_5) {

        }

        $log->intro = "管理员 " . ss('admin_name') . " : " . ss('admin_id') . " 为用户$username $temp_ctl 了 $money $temp_wallet 成功！";
        return $log->save();
    }
}